var CongTrinh;



			
function test1()
{
	alert("#");
	alert($("#danhsachcongtrinh").val());alert("#00");
}

function chuyenCongTrinh()
{
	var value = $("#danhsachcongtrinh").val();
	//alert (value);
	document.location = "index.php?congtrinh="+value;
}

function xoaCT(CTid)
{
	//var value = $("#danhsachcongtrinh").val();
	var r=confirm("Xóa Công Trình ???");
	if (r==true)
	 {
		  	$.get("data/congtrinh.php?xoa="+CTid,function(data,status){
			  alert("Data: " + data + "\nStatus: " + status);
			  location.reload(true);
			});		
 	}
	else
	  {
	  alert("You pressed Cancel!")
	  }
	
}
/*/
var modelCongViec = kendo.data.Model.define({
	id: "CVid",
	
	fields:{
		CVid: {
			type: "number",
			editable: false,	
		},
		MaCV: {
			type: "string",
			editable: true,	
		},
		TenCV: {
			type: "string",
			validation: {
				required: true,	
			}, 
		},
		DVT: {
			type: "string",
			validation: {
				required: true,	
			},
		},
		KhoiLuong: {
			type: "number",	
			validation: {
				required: true,	
			},
		},
		HMid: {
			type: "number",	
			editable: false,
			//defaultValue: e.data.HMid, 
		},
			
	}
	
});
//
var dataCongViec = new kendo.data.DataSource({
	transport: {
		read: "dutoan/congviec/fetch.php",
		update:{
			url: "dutoan/congviec/update.php",
			type: "POST",
				
		},
		destroy: {
			url:"dutoan/congviec/destroy.php",
			type: "POST",
			
		},
		create: {
			url: "dutoan/congviec/create.php",
			type: "POST",
		},
	},
	
	schema: {
		data: "data",
		model: modelCongViec,	
	},
	
	//serverFiltering: true,
	//filter: { field: "MaHM", operator: "eq", value:e.data.HMid },
});
/*/
var modelCongViec;
var dataCongViec;

function themCongViec(e) {
			// get a reference to the current row being initialized 
	var detailRow = e.detailRow;
	modelCongViec = kendo.data.Model.define({
					id: "CVid",
					
					fields:{
						CVid: {
							type: "number",
							editable: false,	
						},
						MaCV: {
							type: "string",
							editable: true,	
						},
						TenCV: {
							type: "string",
							validation: {
								required: true,	
							}, 
						},
						DVT: {
							type: "string",
							validation: {
								required: true,	
							},
						},
						KhoiLuong: {
							type: "number",	
							validation: {
								required: true,	
							},
						},
						HMid: {
							type: "number",	
							editable: false,
							defaultValue: e.data.HMid, 
						},
							
					}
					
				});
				dataCongViec = new kendo.data.DataSource({
					transport: {
						read: "dutoan/congviec/fetch.php",
						update:{
							url: "dutoan/congviec/update.php",
							type: "POST",
								
						},
						destroy: {
							url:"dutoan/congviec/destroy.php",
							type: "POST",
							
						},
						create: {
							url: "dutoan/congviec/create.php",
							type: "POST",
						},
					},
					
					schema: {
						data: "data",
						model: modelCongViec,	
					},
					
					serverFiltering: true,
					filter: { field: "MaHM", operator: "eq", value:e.data.HMid },
				});
				
	// create a subgrid for the current detail row, getting territory data for this employee
	
	detailRow.find(".danhsachcongviec").kendoGrid({
		dataSource: dataCongViec,

		columns: [	
			//	
			{
				title: "CVid",
				field: "CVid",
				width: 1,
			},
			//
			{
				title: "Mã công việc",
				field: "MaCV",
				width: 105,	
			},
			{ 
				title: "Tên công việc", 
				field: "TenCV", 
			},
			{
				title: "Khối lượng",
				field: "KhoiLuong",
				width: 90,	
			},
			{
				title: "Đơn vị tính",
				field: "DVT",
				width: 90,	
			},
			{
				title: "HM",
				field: "HMid",
				width: 100,	
			},
			{ command: [{text:"Sửa", name:"edit"}, {text:"Xóa",name:"destroy"}], title: "Sửa/Xóa", width: "160px" },
		],
		toolbar: [ "create",],
		editable: "inline",
	});
	
					
}

var themHangMuc = function(sender)
{
	var _MaCT = $(sender).data("hangmuc-id");
	//alert(MaCT);	
	//var tenHM = $("#hangmuc_"+MaCT).text();
	var tenHM = document.getElementById("hangmuc_"+_MaCT);
	if (tenHM.value=="") return;
	
	else
	{
		var newHM = new modelHangMuc({
			HMid: null,
			TenHM: tenHM.value,	
			MaCT: _MaCT
		});
		dataHangMuc.add(newHM);
		tenHM.value="";
		//alert(tenHM);
	}
}